package com.example.backend.service.Impl.user.account;
import com.example.backend.Service.Impl.Utils.UserDetailsImpl;
import com.example.backend.pojo.Kobuser;

import com.example.backend.service.user.account.InfoService;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class InfoServiceImpl implements InfoService {
    @Override
    public Map<String, String> getInfo() {
        UsernamePasswordAuthenticationToken authentication =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl loginUser = (UserDetailsImpl) authentication.getPrincipal();
        Kobuser user = loginUser.getUser();
        Map<String, String> map = new HashMap<>();
        map.put("ERROR_MSG", "SUCCESS");
        map.put("ID", user.getUserid().toString());
        map.put("USERNAME", user.getUsername());
        map.put("PHOTO", user.getPhoto());

        return map;
    }
}
